
wa_ll <- readRDS("temp/weighted_full_ll.rds") |> 
  mutate(state = "Washington")

mn_ll <- readRDS("temp/weighted_full_ll_mn.rds") |> 
  mutate(state = "Minnesota")

nc_ll <- readRDS("temp/weighted_full_ll_nc.rds") |> 
  mutate(state = "North Carolina")


all <- rbind(wa_ll, mn_ll, nc_ll) |> 
  filter(pan == "Weighted")

ggplot(all, aes(x = year, y = turnout, linetype = group, shape = group)) + geom_line() +
  geom_point() +
  facet_grid(. ~ state) +
  theme_bc(legend.position = "bottom",
           panel.spacing = unit(.8, "lines")) +
  guides(linetype = guide_legend(title.position = "top", title.hjust = 0.5),
         shape = guide_legend(title.position = "top", title.hjust = 0.5)) +
  labs(x = "Year", y = "Turnout\n(share of voters registered in 2020)",
       linetype = "Treatment Group",
       shape = "Treatment Group",
       caption = "'No Household Deaths' and weighted to mirror 'Household Covid Death' using entropy balancing. Balancing covariates include decedent's age, number of household deaths, historical turnout, latitude, longitude, party affiliation, voter's age, registration date, voter's race / race predictions, gender, party (in WA and NC), block group median income, block group education, and block group population density. 'Household Non-Covid Death' are weighted using the preceding covariates, along with decedent's date of death.") +
  scale_y_continuous(labels = scales::percent)

ggsave("temp/first.png", width = 6, height = 4.5, units = "in")

ggplot(filter(all, year > 2016), aes(x = year, y = turnout, linetype = group, shape = group)) + geom_line() +
  geom_point() +
  facet_grid(. ~ state) +
  theme_bc(legend.position = "bottom",
           panel.spacing = unit(.8, "lines")) +
  guides(linetype = guide_legend(title.position = "top", title.hjust = 0.5),
         shape = guide_legend(title.position = "top", title.hjust = 0.5)) +
  labs(x = "Year", y = "Turnout\n(share of voters registered in 2020)",
       linetype = "Treatment Group",
       shape = "Treatment Group",
       caption = "'No Household Deaths' and weighted to mirror 'Household Covid Death' using entropy balancing. Balancing covariates include decedent's age, number of household deaths, historical turnout, latitude, longitude, party affiliation, voter's age, registration date, voter's race / race predictions, gender, party (in WA and NC), block group median income, block group education, and block group population density. 'Household Non-Covid Death' are weighted using the preceding covariates, along with decedent's date of death.") +
  scale_y_continuous(labels = scales::percent) +
  scale_x_continuous(labels = c(2018, 2020), breaks = c(2018, 2020))

ggsave("temp/first_zoom_in.png", width = 6, height = 4.5, units = "in")

wa_ll <- readRDS("temp/weighted_full_ll_wa_dist.rds") |> 
  mutate(state = "Washington")

mn_ll <- readRDS("temp/weighted_full_ll_mn_dist.rds") |> 
  mutate(state = "Minnesota")

nc_ll <- readRDS("temp/weighted_full_ll_nc.rds") |> 
  mutate(state = "North Carolina") |> 
  filter(pan == "Weighted")


all <- rbind(wa_ll, mn_ll, nc_ll) |> 
  filter(pan == "Weighted")

ggplot(nc_ll, aes(x = year, y = turnout, linetype = group, shape = group)) + geom_line() +
  geom_point() +
  # facet_grid(. ~ state) +
  theme_bc(legend.position = "bottom",
           panel.spacing = unit(.8, "lines")) +
  guides(linetype = guide_legend(title.position = "top", title.hjust = 0.5),
         shape = guide_legend(title.position = "top", title.hjust = 0.5)) +
  labs(x = "Year", y = "Turnout\n(share of voters registered in 2020)",
       linetype = "Treatment Group",
       shape = "Treatment Group",
       caption = "'No Household Deaths' and weighted to mirror 'Household Covid Death' using entropy balancing. Balancing covariates include decedent's age, number of household deaths, historical turnout, latitude, longitude, party affiliation, voter's age, registration date, voter's race / race predictions, gender, party (in WA and NC), block group median income, block group education, and block group population density. 'Household Non-Covid Death' are weighted using the preceding covariates, along with decedent's date of death.") +
  scale_y_continuous(labels = scales::percent)

ggsave("temp/first_dist.png", width = 6, height = 4.5, units = "in")

############################################

j <- bind_rows(
  mutate(readRDS("temp/es_nc.rds"), state = "NC"),
  mutate(readRDS("temp/es_wa.rds"), state = "WA"),
  mutate(readRDS("temp/es_mn.rds"), state = "MN")
) |> 
  rename(up = `97.5 %`,
         lo = `2.5 %`) |> 
  mutate(pt = (up + lo) / 2,
         est = ifelse(est == "any death", "Household Death", "Household Covid Death"))

ggplot(filter(j), aes(x = year, y = pt, ymax = up, ymin = lo,
                                          color = state, shape = state)) +
  facet_grid(.~est)+
  geom_point(position = position_dodge(width = 1), size = 3) +
  geom_errorbar(position = position_dodge(width = 1), width = 0.5) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_bc(legend.position = "bottom") +
  scale_x_continuous(breaks = seq(2014, 2020, 2)) +
  labs(x = "Year", y = "Estimate", color = "State", shape = "State")


ggsave("temp/event_study.png", width = 6, height = 4.5, units = "in")
